const mongoose = require('mongoose');

const { Classify } = require('../../model/classify');

module.exports = async (req, res) => {
    var name = req.fields.name

    var number = await Classify.find({ name }).count()
    if (number == 1) {
        return res.send({
            data: null,
            meta: {
                status: 401,
                msg: '添加失败'
            }
        })
    }
    try {
        var data = await Classify.create({ name })
        // console.log(data);
    } catch {
        return res.send({
            data: null,
            meta: {
                status: 401,
                msg: '添加失败'
            }
        })
    }
    res.send({
        data: null,
        meta: {
            status: 201,
            msg: '添加成功'
        }
    })
}